﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
namespace NJL.WebManage.Attractions
{
    public partial class AddAttractions : BasePage
    {
        NJL.BLL.NJL_ATTRACTION bll = new BLL.NJL_ATTRACTION();
        NJL.Model.NJL_ATTRACTION model = new Model.NJL_ATTRACTION();
        NJL.BLL.NJL_CS_AREA bllArea = new BLL.NJL_CS_AREA();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds = bllArea.GetList("AREA_CODE like '%0000'");
                ddlProvince.DataSource = ds;
                ddlProvince.DataTextField = "AREA_NAME";
                ddlProvince.DataValueField = "AREA_CODE";
                ddlProvince.DataBind();
                if (WEBSITE_CODE == "1")
                {

                }
                else
                {
                    ddlProvince.Visible = false;
                    string ProvinceId = WEBSITE_CODE.Substring(0, 2);
                    DataSet dscity = bllArea.GetList("AREA_CODE like '" + ProvinceId + "%00' and deep=2");
                    ddlCity.DataSource = dscity;
                    ddlCity.DataTextField = "AREA_NAME";
                    ddlCity.DataValueField = "AREA_CODE";
                    ddlCity.DataBind();
                }
                //支付方式
                //cbxLpayment.Items.Add(new ListItem("网上支付", "网上支付"));
                //cbxLpayment.Items.Add(new ListItem("景区现付", "景区现付"));
                ////游玩主题
                //cbxLTheme.Items.Add(new ListItem("爬山", "爬山"));
                //cbxLTheme.Items.Add(new ListItem("滑雪", "滑雪"));
                //cbxLTheme.Items.Add(new ListItem("划船", "划船"));
                ////游客印象
                //cbxLimpression.Items.Add(new ListItem("一般", "一般"));
                //cbxLimpression.Items.Add(new ListItem("好", "好"));
                //cbxLimpression.Items.Add(new ListItem("非常好", "非常好"));
            }

        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            model.ID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(100, 999).ToString();
            model.NJL_SYS_BASE_ID = WEBSITE_CODE;
            model.ATTRACTION_NAME = txtName.Text;  //名称
            model.AREA_CODE = ddlCity.SelectedValue;   //地区
            model.ATTRACTION_ADDRESS = txtAddress.Text;    //地址
            model.ATTRACTION_TAG = txtTag.Text;            //标签
            model.LEVEL = Convert.ToInt32(rbtnLevel.SelectedValue);          //级别
            model.LOCAL_PRICE = Convert.ToDecimal(txtPrice.Text);                  //本站价格
            model.MARKET_PRICE = Convert.ToDecimal(txtSupPrice.Text);              //市场价格
            model.SORT = int.Parse(txtSort.Text.Trim());
            //string payment = "";
            //foreach (ListItem lit in cbxLpayment.Items)
            //{
            //    if (lit.Selected == true)
            //    {
            //        payment += lit.Value + ",";
            //    }
            //}
            //model.PAY_TYPE = payment.Substring(0, payment.Length - 1);                           //支付方式
            //string theme = "";
            //foreach (ListItem lit in cbxLTheme.Items)
            //{
            //    if (lit.Selected == true)
            //    {
            //        theme += lit.Value + ",";
            //    }
            //}

            //model.VISIT_THEME = theme.Substring(0, theme.Length - 1);                         //游玩主题
            //string pression = string.Empty;
            //foreach (ListItem lit in cbxLimpression.Items)
            //{
            //    if (lit.Selected == true)
            //    {
            //        pression += lit.Value + ",";
            //    }
            //}
            //model.TOURIST_IMPRESSION = pression.Substring(0, pression.Length - 1);//游客印象       
            //model.MANUAL_DESCRIPTION = txtDesc.Text;                              //旅游指南介绍
            //model.MANUAL_TRAFFIC = txtTraffic.Text;                               //旅游指南交通
            //model.MANUAL_FOOD = txtFood.Text;                                     //美食
            //model.MANUAL_SHOP = txtBuy.Text;                                      //购物
            //model.MANUAL_OTHER = txtOther.Text;                                   //其他
            model.TICKET_NOTICE = txtTicketNotice.Text;                           //购票须知
            if (FileUpload1.HasFile)
            {
                model.IMAGE_CODE = SaveUploadFile(Request.Files);
            }
            model.SEO_DESCRIPTION = txtDescription.Text.Trim();
            model.SEO_KEYWORDS = txtKeyWords.Text.Trim();
            model.SEO_TITLE = txtTitle.Text.Trim();
            model.CREATE_USER_NAME = USER_NAME;
            model.CREATE_USER_ID = USER_ID;
            model.CREATE_DATE_TIME = DateTime.Now;
            model.PUBLISH_DATE_TIME = DateTime.Now;
            model.IS_TOP = 0;
            model.IS_INDEX = 0;
            model.IS_PUBLISH = 0;
            if (bll.Add(model))
            {


                Royalsoft.Common.MessageBox.ShowAndRedirect(this, "添加成功", "AddAttractions.aspx");
                #region 标签处理
                NJL.BLL.NJL_CS_TAG bllTag = new BLL.NJL_CS_TAG();
                NJL.Model.NJL_CS_TAG modelTag = new Model.NJL_CS_TAG();
                char[] tagtxt1 = { ',', '，'};
                string[] tag = txtTag.Text.Trim().Split(tagtxt1);
                foreach (string strtag in tag)
                {
                    DataSet ds = bllTag.GetList("TAG='" + strtag + "' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        modelTag = bllTag.GetModel(ds.Tables[0].Rows[0][0].ToString());
                        if (modelTag != null)
                        {
                            if (modelTag.USED_COUNT != null)
                            {
                                modelTag.USED_COUNT += 1;
                                if (bllTag.Update(modelTag))
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        if (strtag != "")
                        {
                            modelTag.ID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random(Guid.NewGuid().GetHashCode()).Next(100, 999).ToString();
                            modelTag.IS_SYS_TAG = 0;
                            modelTag.TAG = strtag;
                            modelTag.CREATE_DATE_TIME = DateTime.Now;
                            modelTag.NJL_SYS_BASE_ID = WEBSITE_CODE;
                            modelTag.SEARCH_COUNT = 0;
                            modelTag.TAG_TYPE = "1";  //景点是1
                            modelTag.USED_COUNT = 0;
                            modelTag.AREA_CODE = ddlCity.SelectedValue;
                            bllTag.Add(modelTag);
                        }
                    }
                }
                #endregion 

            }
        }

        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ProvinceId = ddlProvince.SelectedValue.Substring(0, 2);
            DataSet ds = bllArea.GetList("AREA_CODE like '" + ProvinceId + "%00' and deep=2");
            ddlCity.DataSource = ds;
            ddlCity.DataTextField = "AREA_NAME";
            ddlCity.DataValueField = "AREA_CODE";
            ddlCity.DataBind();
        }

    }
}